package com.zhaoyun.aar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.zhaoyun.ledsdk.serial.ChargeSerialController;
import com.zhaoyun.ledsdk.serial.IChargeSerial;
import com.zhaoyun.ledsdk.serial.LuminanceListener;


public class MainActivity extends AppCompatActivity implements LuminanceListener{
    IChargeSerial iChargeSerial;
    TextView textView;
    int tmp = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.txt);

        iChargeSerial = new ChargeSerialController(this);
        iChargeSerial.openPort();
        iChargeSerial.setListener(this);

        findViewById(R.id.del).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(tmp == 0){
                    return;
                }
                tmp--;
                textView.setText(String.valueOf(tmp));
                iChargeSerial.openCharge(tmp);
            }
        });

        findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(tmp == 100){
                    return;
                }
                tmp++;
                textView.setText(String.valueOf(tmp));
                iChargeSerial.openCharge(tmp);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        iChargeSerial.closePort();
    }

    @Override
    public void result(String s) {

    }
}
